package com.duleme.servlet;

import com.duleme.common.EncodeUtils;
import com.duleme.entity.Book;
import com.duleme.service.BookService;
import com.duleme.service.impl.BookServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "BuyBookServlet",urlPatterns = "/data/buyBook")
public class BuyBookServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        EncodeUtils.setEncoding(request,response);
        int bookID = Integer.valueOf(request.getParameter("bookID"));
        BookService bookService = new BookServiceImpl();
        Book book = bookService.getBook(bookID);
        if (book==null){
            request.getRequestDispatcher("index.html").forward(request,response);
        }else {
            request.setAttribute("book",book);
            request.getRequestDispatcher("../Goods_Information.jsp").forward(request,response);
        }
    }
}
